package com.tsd.jxc.stock.entity;

import com.tsd.core.constants.Constants;
import com.tsd.core.utils.ListUtil;
import com.tsd.jxc.stock.StockConstants;
import com.tsd.jxc.vo.PrintVo;
import com.tsd.system.entity.SysUserExt;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * 盘点信息扩展
 *
 * @author Hillpool
 * @date 2022/07/29 15:06:33
 */
@ApiModel(description = "盘点信息扩展")
public class JxcStockInventoryExt extends JxcStockInventory implements Serializable {

    @ApiModelProperty(value = "保存item的detail信息")
    private List<JxcStockInventoryItemExt> item_list;

    @ApiModelProperty(value = "保存仓库名称")
    private String warehouse_name;

    private List<String> sid_list;

    private List<JxcStockInventoryItemExt> surplus_list;
    private List<JxcStockInventoryItemExt> loss_list;

    public List<JxcStockInventoryItemExt> getItem_list() {
        return item_list;
    }

    public void setItem_list(List<JxcStockInventoryItemExt> item_list) {
        this.item_list = item_list;
    }

    public String getWarehouse_name() {
        return warehouse_name;
    }

    public void setWarehouse_name(String warehouse_name) {
        this.warehouse_name = warehouse_name;
    }

    public List<String> getSid_list() {
        return sid_list;
    }

    public void setSid_list(List<String> sid_list) {
        this.sid_list = sid_list;
    }

    public List<JxcStockInventoryItemExt> getSurplus_list() {
        return surplus_list;
    }

    public void setSurplus_list(List<JxcStockInventoryItemExt> surplus_list) {
        this.surplus_list = surplus_list;
    }

    public List<JxcStockInventoryItemExt> getLoss_list() {
        return loss_list;
    }

    public void setLoss_list(List<JxcStockInventoryItemExt> loss_list) {
        this.loss_list = loss_list;
    }

    public PrintVo convert2Print(SysUserExt userExt) {
        PrintVo vo = new PrintVo();
        vo.setCode(this.getCode());
        vo.setCreator_name(this.getCreator_name());
        vo.setCreate_date(this.getCreate_date());
        vo.setCheck_date(this.getCheck_date());
        vo.setWarehouse_name(this.getWarehouse_name());
        vo.setState(this.getState());
        vo.setAuditor_name(this.getAuditor_name());
        vo.setAudit_date(this.getAudit_date());
        vo.setUpdate_stock(this.getUpdate_stock());
        vo.setUpdate_stock_date(this.getUpdate_stock_date());
        List<PrintVo> itemList = ListUtil.map(this.getItem_list(), JxcStockInventoryItemExt::convert2Print);
        vo.setItem_list(itemList);
        if (userExt != null) {
            vo.setPrint_name(userExt.getName());
        }
        vo.setPrint_datetime(new Date());
        return vo;
    }

    public JxcStockInbillExt genInBill(String warehouse_sid) {
        JxcStockInbillExt inbillExt = new JxcStockInbillExt();
        inbillExt.setWarehouse_sid(warehouse_sid);
        inbillExt.setSrc_sid(this.getSid());
        inbillExt.setSrc_code(this.getCode());
        inbillExt.setIn_type(StockConstants.IN_TYPE_SURPLUS);
        inbillExt.setIn_date(new Date());
        inbillExt.setAudit_state(Constants.DR_VALID);
        inbillExt.setExecute_state(Constants.DR_VALID);
        List<JxcStockInventoryItemExt> detailExtList = this.getSurplus_list();
        List<JxcStockInbillItemExt> itemExtList = ListUtil.map(detailExtList, t -> t.genInBillItem());
        inbillExt.setItem_list(itemExtList);
        return inbillExt;
    }

    public JxcStockOutbillExt genOutBill(String warehouse_sid) {
        JxcStockOutbillExt outBillExt = new JxcStockOutbillExt();
        outBillExt.setWarehouse_sid(warehouse_sid);
        outBillExt.setOut_type(StockConstants.OUT_TYPE_LOSS);
        outBillExt.setOut_date(new Date());
        outBillExt.setSrc_sid(this.getSid());
        outBillExt.setSrc_code(this.getCode());
        outBillExt.setExecute_state(Constants.DR_VALID);
        outBillExt.setAudit_state(Constants.DR_VALID);
        List<JxcStockInventoryItemExt> detailExtList = this.getLoss_list();
        List<JxcStockOutbillItemExt> itemExtList = ListUtil.map(detailExtList, t -> t.genOutBillItem());
        outBillExt.setItem_list(itemExtList);
        return outBillExt;
    }

}
